package behavioralPattern.observer.example03;

import behavioralPattern.observer.example02.LotteryResult;

/**
 * 开奖服务接口
 */
public abstract class LotteryService {

    private EventManager eventManager;

    public LotteryService() {
        // 设置事件的类型
        eventManager = new EventManager(EventManager.EventType.MQ,EventManager.EventType.Message);
        // 订阅
        eventManager.subscribe(EventManager.EventType.Message,new Message());
        eventManager.subscribe(EventManager.EventType.MQ,new MQ());
    }

    public LotteryResult lotteryAndMsg(String uid){
        LotteryResult result = lottery(uid);
        // 通知
        eventManager.notifySubject(EventManager.EventType.Message,result);
        eventManager.notifySubject(EventManager.EventType.MQ,result);

        return result;
    }

    public abstract LotteryResult lottery(String uid);
}
